/**
 * @author        hejiyang <silentmanager@163.com>
 * @date          2024-11-10 00:12:11
 * Copyright © YourCompanyName All rights reserved
 */
import request from '@/config/axios'
import { ApiResponse } from '@/types/ref'

// (公海)客户导入待开发
export const putPoolCustomer = async (ids: string) => {
  return await request.put({ url: `/crm/customer/put-pool?ids=${ids}` })
}

// (公海)筛选客户导入待开发
export const putPoolAll = async (data: any) => {
  return await request.put({ url: '/crm/customer/put-pool-all', data })
}

// 标记客户
export const updateTagCustomer = async (data: { ids: string; tag: string }) => {
  return await request.request<ApiResponse<any>>({
    url: `/crm/customer/updateTag?ids=${data.ids}&tag=${data.tag}`,
    method: 'PUT'
  })
}

// 客户标签下拉
export const tagListCustomer = async () => {
  return await request.get<
    {
      name: string
      tag: string
    }[]
  >({ url: `/crm/customer/tagList` })
}

// 回收客户
export const recyclingCustomer = async (data) => {
  return await request.put({ url: `/crm/customer/recycling`, data })
}

// (公海)导入客户
export const importCustomer = async (data) => {
  return await request.post({ url: `/crm/customer/import`, data })
}
export interface pageCustomerUser {
  id: number // 用户ID
  name: string // 用户姓名
  age: number // 用户年龄
  sex: string // 性别
  mobile: string // 手机号
  telephone: string // 固定电话
  email: string // 邮箱地址
  qq: string // QQ号码
  wechat: string // 微信号
  areaId: string // 区域ID
  areaName: string // 区域名称
  detailAddress: string // 详细地址
  goodsName: string // 商品名称
  goodsNumber: number // 商品数量
  goodsAmount: number // 商品金额
  orderNo: string // 订单号
  creator: string // 创建者ID
  creatorName: string // 创建者姓名
  ownerUserId: string // 拥有者用户ID
  ownerUserName: string // 拥有者用户名
  ownerUserDeptName: string // 拥有者部门名称
  ownerTime: string // 拥有时间
  remark: string // 备注
  level: string // 用户级别
  updateTime: string // 最后更新时间
  createTime: string // 创建时间
}

// 待开发客户列表
export const pageCustomer = async (params) => {
  return await request.get<{ list: pageCustomerUser[]; total: number }>({
    url: `/crm/customer/page`,
    params
  })
}

export interface UserDetails {
  id: number // 用户ID
  name: string // 用户姓名
  age: number // 用户年龄
  sex: string // 性别
  mobile: string // 手机号
  telephone: string // 固定电话
  email: string // 邮箱地址
  qq: string // QQ号码
  wechat: string // 微信号
  areaId: string // 区域ID
  areaName: string // 区域名称
  detailAddress: string // 详细地址
  goodsName: string // 商品名称
  goodsNumber: number // 商品数量
  goodsAmount: number // 商品金额
  orderNo: string // 订单号
  creator: string // 创建者ID
  creatorName: string // 创建者姓名
  ownerUserId: string // 拥有者用户ID
  ownerUserName: string // 拥有者用户名
  ownerUserDeptName: string // 拥有者部门名称
  ownerTime: string // 拥有时间
  remark: string // 备注
  updateTime: string // 最后更新时间
  createTime: string // 创建时间
}

// (公海)客户列表(其他参考待开发)
export const poolPageCustomer = async (params) => {
  return await request.get<{ list: UserDetails[]; total: number }>({
    url: `/crm/customer/pool-page`,
    params
  })
}

// 转派客户（分配客户）
export const distributeCustomer = async (data: { ids: number[]; ownerUserId: string }) => {
  return await request.request({
    url: `/crm/customer/distribute`,
    method: 'PUT',
    data
  })
}

// 客户备注
export const createFollowUpRecord = async (data: { bizId: number; content: string }) => {
  return await request.post({ url: `/crm/follow-up-record/create`, data })
}

// 删除客户备注
export const deleteFollowUpRecord = async (id: string) => {
  return await request.delete({
    url: `/crm/follow-up-record/delete?id=${id}`
  })
}
export interface pageFollowUpRecordRes {
  id: number
  content: string
  creatorName: string
  createTime: string
}
// 分页获取客户备注列表
export const pageFollowUpRecord = async (params) => {
  return await request.get<{
    list: pageFollowUpRecordRes[]
    total: number
  }>({ url: `/crm/follow-up-record/page`, params })
}

// 申请/领取客户
export const receiveCustomer = async (number: number, level: string) => {
  return await request.request({
    url: `/crm/customer/receive?number=${number}&level=${level}`,
    method: 'PUT'
  })
}

// 客户类型数量
export const countByLevelCustomer = async (params) => {
  return await request.get({ url: `/crm/customer/countByLevel`, params })
}

// 客户操作记录
export const pageOperateLog = async (params) => {
  return await request.get({ url: `/crm/operate-log/page`, params })
}

// （公海）导入模版
export const getImportTemplateCustomer = async () => {
  return await request.download({
    url: `/crm/customer/get-import-template`
  })
}

export interface CustomerEmitReq {
  id: string
  name: string
  detailAddress: string
  sex: string
}
// 编辑客户
export const updateCustomer = async (data: CustomerEmitReq) => {
  return await request.put({ url: `/crm/customer/update`, data })
}

// 申请客户对应类型数量
export interface ByLevelCountCustomerRes {
  level: string
  count: number
}
export const byLevelCountCustomer = async () => {
  return await request.get<ByLevelCountCustomerRes[]>({ url: `/crm/customer/byLevelCount` })
}

export interface SimpleListDeptRes {
  id: number
  name: string
  parentId: number
}
// 获取部门
export const simpleListDept = async () => {
  return await request.get<SimpleListDeptRes[]>({
    url: `/system/dept/simple-list?teamGroup=1`
  })
}
export interface SimpleListUserRes {
  deptId: number
  deptName: string
  id: number
  nickname: string
}
//通过部门获取角色
export const simpleListUser = async (deptId: string) => {
  return await request.get<SimpleListUserRes[]>({
    url: `/system/user/simple-list?deptId=${deptId}`
  })
}

// 标记黑名单
export const editBlacklistStatus = async (mobile: string, status: boolean) => {
  return await request.request({
    url: `/crm/customer/editBlacklistStatus?mobile=${mobile}&status=${status}`,
    method: 'PUT'
  })
}
